﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HZ.DrugTrade.Web;
using HZ.DrugTrade.Model;
using HZ.DrugTrade.Model.Enum;
using HZ.DrugTrade.IBLL;
using HZ.DrugTrade.BLLFactory;
using System.Data;
namespace HZ.DrugTrade.Web.Hospitals.Collection
{
    public partial class InvoicePaydeail : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                ShowGIV();//显示
            }
        }
        /// <summary>
        /// 显示giv
        /// </summary>
        private void ShowGIV()
        {
            string ShidInvoice = new HZ.Common.ConvertHelper(Request.QueryString["IDP"]).String;
            if (ShidInvoice != "")
            {
                int totalDrugrecord = 0;
                HZ.DrugTrade.Model.Query.InvoiceDistribution qryWhere = new HZ.DrugTrade.Model.Query.InvoiceDistribution();
                //qryWhere.Append = "  InvoiceSerialID in (" + ShidInvoice.Replace("'", "") + ")";               //updated by lhl  2009-08-27
                qryWhere.Append = "  InvoiceSerialID in (" + ShidInvoice + ")";
                qryWhere.SortFields = " Goodsid,OrderName ASC ";
                IList<Model.View.InvoiceDistribution> lstInvoiceDistribution = new List<Model.View.InvoiceDistribution>();
                IBLL_Purchase iPurchase = Factory.BLL_Purchase();
                //AspNetPager1.PageSize = Constants.GRIDVIEW_PAGE_SIZE;
                lstInvoiceDistribution = iPurchase.GetInvoiceDistributionByWhere(qryWhere, AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out totalDrugrecord);
                this.gvGoods.AutoGenerateColumns = false;
                this.gvGoods.DataSource = lstInvoiceDistribution;
                this.gvGoods.DataBind();
                AspNetPager1.RecordCount = totalDrugrecord;
            }
            if (this.gvGoods.Rows.Count > 0)
            {
                this.btnExport.Visible = true;
            }
        }
        /// <summary>
        /// 翻页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void AspNetPager1_OnPageChanged(object sender, EventArgs e)
        {
            ShowGIV();
        }

        /// <summary>
        ///  2009-11-14 导出功能
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnExport_Click(object sender, EventArgs e)
        {
            string ShidInvoice = new HZ.Common.ConvertHelper(Request.QueryString["IDP"]).String;
            if (ShidInvoice != "")
            {

                HZ.DrugTrade.Model.Query.InvoiceDistribution model = new HZ.DrugTrade.Model.Query.InvoiceDistribution();
                IBLL_Purchase iPurchase = Factory.BLL_Purchase();
                model.Append = "InvoiceSerialID in (" + ShidInvoice + ")";
                model.SortFields = " Goodsid,OrderName ASC";
                int totalCount = 0;
                IList<Model.View.InvoiceDistribution> lstInvoiceDistribution = iPurchase.GetInvoiceDistributionByWhere(model, 1, 0, out totalCount);
                DataTable dt = HZ.Data.ModelConvert.GetDataTableFromModel(lstInvoiceDistribution);
                HZ.Excel.ExcelHelper.ExportDataForWeb(dt, gvGoods);


            }
        }
    }
}
